﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.cn
{
    public partial class orderlist : System.Web.UI.Page
    {
        // Fields
        public string ordermsg = "";

        // Methods
        private void Bind()
        {
            string str;
            string str3 = "";
            if ((this.Session["username"] != null) && !string.IsNullOrEmpty(base.Request.Form["orderkey"]))
            {
                str = string.Concat(new object[] { "select orderid,ordercode,cname,pay,totalprice,states,ordertime,paytime,shiptime,sendCompany,sendCode,isnull(senddate1,'') as senddate1 ,SendUrl,SendTelphone,SendPerson,SendPersonCompany,SendPersonAddress from DB_Order where memberid=", this.Session["memberid"], " and ordercode='", base.Request.Form["orderkey"], "'", " and cname='", base.Request.Form["cname"], "'" });
            }

            else if (this.Session["username"] != null)
            {
                str = "select orderid,ordercode,cname,pay,totalprice,states,ordertime,paytime,shiptime,sendCompany,sendCode,isnull(senddate1,'') as senddate1 ,SendUrl,SendTelphone,SendPerson,SendPersonCompany,SendPersonAddress from DB_Order where memberid=" + this.Session["memberid"] + "";
            }

            else if (!string.IsNullOrEmpty(base.Request.Form["cardcode"]) && !string.IsNullOrEmpty(base.Request.Form["cardpas"]))
            {
                str = string.Format("select o.orderid,o.ordercode,o.cname,o.pay,o.totalprice,o.states,o.ordertime,o.paytime,o.shiptime,o.sendCompany,o.sendCode,isnull(o.senddate1,'') as senddate1 ,o.SendUrl,o.SendTelphone,o.SendPerson,o.SendPersonCompany,o.SendPersonAddress from DB_Order o join tbOrderAccount oc on o.OrderCode = oc.OrderCode"
                                   + "  join db_Card c on oc.CardId = c.CardId where c.CardCode={0} and c.CardPas='{1}' "
                                   , base.Request.Form["cardcode"]
                                   , Gift.Security.DESEncrypt.Encrypt(base.Request.Form["cardpas"])
                                   );
            }
            else 
            {
                str = "select orderid,ordercode,cname,pay,totalprice,states,ordertime,paytime,shiptime,sendCompany,sendCode,isnull(senddate1,'') as senddate1 ,SendUrl,SendTelphone,SendPerson,SendPersonCompany,SendPersonAddress from DB_Order where ordercode='" + base.Request.Form["orderkey"] + "' and cname1='" + base.Request.Form["cname"] + "'";
            }
            DataTable table = SQLAccess.GreatDs(str).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.ordermsg = this.ordermsg + "<tr>";
                    string ordermsg = this.ordermsg;
                    this.ordermsg = ordermsg + "<td height='28' align='center' bgcolor='#FFFFFF'><a href='order_details.aspx?oid=" + row["orderid"].ToString() + "' target=_blank>" + row["ordercode"].ToString() + "</a></td>";

                    //   this.ordermsg = this.ordermsg + "订单总金额 : <span class='text_red'>" + string.Format("{0:f}", Convert.ToSingle(row["totalprice"])) + " 元</span></div></td>";
                    if (row["states"].ToString() == "1")
                    {
                        str3 = "备货中";
                    }
                    else if (row["states"].ToString() == "2")
                    {
                        str3 = "已发货";
                    }
                    else if (row["states"].ToString() == "3")
                    {
                        str3 = "已完成";
                    }
                    else if (row["states"].ToString() == "5")
                    {
                        str3 = "已取消";
                    }
                    else
                    {
                        str3 = "新订单";
                    }

                    this.ordermsg = this.ordermsg + "<td align='center' bgcolor='#FFFFFF'><span class='text_red'><font color='red'>" + str3 + "</font></span></td>";

                    string sCompany = row["sendCompany"].ToString();
                    string sSendDate1 = row["SendDate1"].ToString() == "" ? string.Empty : DateTime.Parse(row["SendDate1"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    if (sSendDate1.Contains("1900-01-01")) sSendDate1 = string.Empty;
                    this.ordermsg = this.ordermsg + "<td align='left' bgcolor='#FFFFFF'><div style='margin:5px; text-align:left;'>物流公司:<span class='text_red'>" + sCompany + "</span> <br />"
                                                       + "物流单号:" + row["sendCode"].ToString() + "<br />"
                                                       + "物流查询网址:<a href='" + row["SendUrl"].ToString() + "' target='_blank'>" + row["SendUrl"].ToString() + "</a><br />"
                                                       + "物流查询电话:" + row["SendTelphone"].ToString() + "<br />"
                                                       + "发货时间:" + sSendDate1 + "<br />";

                    this.ordermsg = this.ordermsg + "</span></div></td></tr>";
                }
            }
            else
            {
                this.ordermsg = "<tr bgcolor='#FFFFFF'><td colspan='3'>没有符合查询条件的记录，请确认查询关键字是否正确！'</td></tr>";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack && ((this.Session["memberid"] != null) || (base.Request.Form["orderkey"] != null)))
            {
                this.Bind();
            }
        }

    }
}